package main

import (
	"fmt"
	"time"
)

func foo() {
	fmt.Println("foo功能开始...")
	time.Sleep(2 * time.Second)
	fmt.Println("foo功能结束...")
}

func bar() {
	fmt.Println("bar功能开始...")
	time.Sleep(3 * time.Second)
	fmt.Println("bar功能结束...")
}

func getTimer(f func()) func() {
	return func() {
		var startTime = time.Now().Unix()
		f()
		var endTime = time.Now().Unix()
		fmt.Printf("函数执行时长: %d秒\n", endTime-startTime)
	}
}

func main() {
	foo := getTimer(foo)
	foo()
	bar := getTimer(bar)
	bar()
}
